package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KWriteOff;
import com.ruoyi.qsng.service.IKWriteOffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品-我的核销Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/qsng/off")
@Api(tags = "pc--商品-我的核销Controller")
public class KWriteOffController extends BaseController {
    @Autowired
    private IKWriteOffService kWriteOffService;

    /**
     * 查询商品-我的核销列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:off:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询商品-我的核销列表")
    public TableDataInfo list(KWriteOff kWriteOff) {
        startPage();
        List<KWriteOff> list = kWriteOffService.selectKWriteOffDataList(kWriteOff);
        return getDataTable(list);
    }

    /**
     * 导出商品-我的核销列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:off:export')")
    @Log(title = "商品-我的核销", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出商品-我的核销列表")
    public void export(HttpServletResponse response, KWriteOff kWriteOff) {
        List<KWriteOff> list = kWriteOffService.selectKWriteOffDataList(kWriteOff);
        ExcelUtil<KWriteOff> util = new ExcelUtil<KWriteOff>(KWriteOff.class);
        util.exportExcel(response, list, "商品-我的核销数据");
    }

    /**
     * 获取商品-我的核销详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:off:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取商品-我的核销详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kWriteOffService.selectKWriteOffById(id));
    }

    /**
     * 新增商品-我的核销
     */
    @PreAuthorize("@ss.hasPermi('qsng:off:add')")
    @Log(title = "商品-我的核销", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增商品-我的核销")
    public AjaxResult add(@RequestBody KWriteOff kWriteOff) {
        return toAjax(kWriteOffService.insertKWriteOff(kWriteOff));
    }

    /**
     * 修改商品-我的核销
     */
    @PreAuthorize("@ss.hasPermi('qsng:off:edit')")
    @Log(title = "商品-我的核销", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改商品-我的核销")
    public AjaxResult edit(@RequestBody KWriteOff kWriteOff) {
        return toAjax(kWriteOffService.updateKWriteOff(kWriteOff));
    }

    /**
     * 删除商品-我的核销
     */
    @PreAuthorize("@ss.hasPermi('qsng:off:remove')")
    @Log(title = "商品-我的核销", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除商品-我的核销")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kWriteOffService.deleteKWriteOffByIds(ids));
    }
}
